package com.wan.service.role;

import com.wan.dao.BaseDao;
import com.wan.dao.role.RoleDao;
import com.wan.dao.role.RoleDaoImpl;
import com.wan.pojo.Role;
import org.junit.Test;

import java.sql.Connection;
import java.util.List;

public class RoleServiceImpl implements RoleService{

    // 引入Dao
    private RoleDao roleDao;
    public RoleServiceImpl(){
        this.roleDao = new RoleDaoImpl();
    }

    @Override
    public List<Role> getRoleList() {

        Connection conn  = null;
        List<Role> roleList = null;
        try {
            conn = BaseDao.getConnection();
            roleList = roleDao.getRoleList(conn);
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            BaseDao.closeResource(conn,null,null);
        }
        return roleList;
    }
    @Test
    public void test() {
        RoleService roleService = new RoleServiceImpl();
        List<Role> roleList = roleService.getRoleList();
        for (Role role: roleList) {
            System.out.println(role.getRoleName());
        }
    }
}
